////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                                            //
//                                                         WNProject                                                          //
//                                                                                                                            //
//            This file is distributed under the BSD 2-Clause open source license. See License.txt for details.               //
//                                                                                                                            //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once

#ifndef __WN_SCRIPTING_IDENTIFIER_MAP_H__
#define __WN_SCRIPTING_IDENTIFIER_MAP_H__

#include "WNScripting/inc/WNScriptingConfig.h"
#include "WNScripting/inc/WNIdentifierElement.h"
#include "WNConcurrency/inc/WNCriticalSection.h"
#include "WNCore/inc/WNFunctions.h"

#include <string>

using namespace WNConcurrency;

namespace WNScripting {
    const WNIdentifierElement WNInvalidIdentifier = WN_NULL;

    class WNIdentifierMap {
    public:
        WNIdentifierMap();
        WNIdentifierElement GetIdentifier(const WN_CHAR * _identifier, WN_SIZE_T _length);
        const WN_CHAR* GetStringFromIdentifier(WNIdentifierElement _element) const;

    private:
        WN_UNORDERED_MAP<std::string, char*> mIdentMap;
        WNIdentifierElement mCurValue;

        #ifdef WN_SCRIPTING_MULTITHREADED_PARSING
            WNCriticalSection mIdentifierLock;
        #endif
    };
}

template <>
WN_INLINE WN_BOOL WNIsValid(WNScripting::WNIdentifierElement _value) {
    return(_value != WNScripting::WNInvalidIdentifier);
}
#endif // __WN_SCRIPTING_IDENTIFIER_MAP_H__